<template>
  <h2>shallowReactive和shallowRef</h2>
  <h3>m1:{{ m1 }}</h3>
  <h3>m2:{{ m2 }}</h3>
  <h3>m3:{{ m3 }}</h3>
  <h3>m4:{{ m4 }}</h3>
  <button @click="update">更新数据</button>
</template>

<script lang="ts">
import {
  defineComponent,
  reactive,
  shallowReactive,
  ref,
  shallowRef
} from 'vue'

export default defineComponent({
  name: 'App',
  setup() {
    const m1 = reactive({
      name: '鸣人',
      age: 20,
      car: {
        name: '奔驰',
        color: '红色'
      }
    })
    const m2 = shallowReactive({
      name: '鸣人',
      age: 20,
      car: {
        name: '奔驰',
        color: '红色'
      }
    })
    const m3 = ref({
      name: '鸣人',
      age: 20,
      car: {
        name: '奔驰',
        color: '红色'
      }
    })
    const m4 = shallowRef({
      name: '鸣人',
      age: 20,
      car: {
        name: '奔驰',
        color: '红色'
      }
    })

    console.log(m3, m4)

    const update = () => {
      // m1.car.name = '本田'
      // m2.car.name += '==='
      // m3.value.name = '本田'
      m4.value.name = '本田'
    }
    return {
      m1,
      m2,
      m3,
      m4,
      update
    }
  }
})
</script>

<style scoped>
</style>